﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
using System.Web;

namespace TPCN.Commons
{
    public class EmailHelper
    {

        public enum EmailType
        {
            GMAIL, YAHOO
        };

        public static void SendMail(EmailType TYPE, string email, string password, string customer, string saler, string subject, string body)
        {
            MailMessage mail = new MailMessage();
            SmtpClient smtp = new SmtpClient();
            smtp.EnableSsl = true;
            switch (TYPE)
            {
                case EmailType.GMAIL:
                    smtp.Host = "smtp.gmail.com";
                    break;
                case EmailType.YAHOO:
                    smtp.Host = "plus.smtp.mail.yahoo.com";
                    break;
            }
            smtp.Port = 587;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.UseDefaultCredentials = false;
            smtp.Timeout = 20000;
            smtp.Credentials = new NetworkCredential(email, password);
            mail.Subject = subject;
            mail.SubjectEncoding = Encoding.UTF8;
            mail.Body = body;
            mail.BodyEncoding = Encoding.UTF8;
            mail.From = new MailAddress(email);
            mail.Sender = new MailAddress(email);
            mail.To.Add(new MailAddress(customer));
            mail.To.Add(new MailAddress(saler));
            mail.IsBodyHtml = true;
            mail.Priority = MailPriority.High;
            try
            {
                smtp.Send(mail);
            }
            catch (Exception)
            {

            }
            //IMailSender objMail;
            //objMail = new MailSender();
            //switch (TYPE)
            //{
            //    case EmailType.GMAIL:
            //        objMail.Host = "smtp.gmail.com";
            //        break;
            //    case EmailType.YAHOO:
            //        objMail.Host = "plus.smtp.mail.yahoo.com";
            //        break;
            //}
            //objMail.From = email;
            //objMail.FromName = "Thực phẩm chức năng AZ";

            //objMail.AddAddress(customer);
            //objMail.AddAddress(saler);

            //objMail.Subject = subject;
            //objMail.Body = body;

            //try
            //{
            //    objMail.Send();
            //}
            //catch(Exception)
            //{

            //}
        }
    }
}
